#include "stm32f10x.h"                  // Device header
#include "Delay.h"

#include "LED.h"
#include "Key.h"
#include "OLED.h"
#include "W25Q64.h"

uint8_t MID = 0;
uint16_t DID = 0;

uint8_t ArrayWrite[] = {0xA1, 0xB2, 0xC3, 0xD4};
uint8_t ArrayRread[4];

#define WRITE_TEST 1
#define ERASE_TEST 0

int main(void)
{
	// 初始化
	OLED_Init();

	// 初始化 W25Q64
	W25Q64_Init();

	// Title:  
	OLED_ShowString(1, 1, "MID:   DID:");
	OLED_ShowString(2, 1, "W:");
	OLED_ShowString(3, 1, "R:");
	
	// 读取芯片ID: 
	W25Q64_ReadID(&MID, &DID);
	OLED_ShowHexNum(1, 5, MID, 2);
	OLED_ShowHexNum(1, 12, DID, 4);

#if WRITE_TEST
	
	// 写入测试
	// 1. 写之前擦除扇区
	W25Q64_SectorErase(0x000000);
	// 2. 写入
#if !ERASE_TEST
	W25Q64_PageProgram(0x000000, ArrayWrite, 4);
#endif

#endif

	// 读取测试
	W25Q64_ReadData(0x000000, ArrayRread, 4);
	
	
	// OLED 输出读写测试结果
#if WRITE_TEST
	OLED_ShowHexNum(2, 3, ArrayWrite[0], 2);
	OLED_ShowHexNum(2, 6, ArrayWrite[1], 2);
	OLED_ShowHexNum(2, 9, ArrayWrite[2], 2);
	OLED_ShowHexNum(2, 12, ArrayWrite[3], 2);
#endif

	OLED_ShowHexNum(3, 3, ArrayRread[0], 2);
	OLED_ShowHexNum(3, 6, ArrayRread[1], 2);
	OLED_ShowHexNum(3, 9, ArrayRread[2], 2);
	OLED_ShowHexNum(3, 12, ArrayRread[3], 2);
	
	
	while(1)
	{
		W25Q64_ReadData(0x000000, ArrayRread, 4);
	}
}